// pages/order_detail/order_detail.js
var app = getApp();
var ApiUrl = app.globalData.ApiUrl;
var key = "";
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var that = this;
      key = options.key;
      var order_id = options.order_id;

      wx.request({
        url: ApiUrl + '/index.php?act=member_order&op=order_info',
        data: { 'key': key,'type':"123",'order_id':order_id},
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        method: 'get',
        success:function(res){
           
            that.setData({
              order_info:res.data.datas.order_info,
              key:key
            });
            wx.request({
              url: ApiUrl + '/index.php?act=member_order&op=get_current_deliver',
              data: { 'key':key,'order_id':order_id},
              header: {
                'content-type': 'application/x-www-form-urlencoded'
              },
              method: 'post',
              success: function (deliver) {                 
                that.setData({
                  deliver_info: deliver.data.datas.deliver_info,                 
                });
              }
            })
            
        }
    })
  },
  call: function (val) {
    
    var phoneNumber = val.currentTarget.dataset.phonenumber;  
      wx.makePhoneCall({
        phoneNumber: "'"+phoneNumber+"'"  
      })
  },
  //取消订单
  cancel_order:function(result){ 
    key = result.currentTarget.dataset.key;
    var order_id = result.currentTarget.dataset.order_id;
    wx.showModal({
      title:'',
      content: '确定要取消订单',
      success: function (res) {        
          if (res.confirm) {
             
              wx.request({
                url: ApiUrl + "/index.php?act=member_order&op=order_cancel",
                data: { 'key': key, 'order_id': order_id },
                header: {
                  'content-type': 'application/x-www-form-urlencoded'
                },
                method: 'post',
                success: function (res) {
                   if(res.data.datas==1){
                     wx.showToast({
                       title: '取消成功',
                       icon: 'success',
                       duration: 2000
                     })
                     wx.redirectTo({
                       url: '/pages/order_detail/order_detail?order_id='+order_id+"&key="+key,
                     })
                   }                 
                }
              })
          } 
      }
    })    
  },
 
  //确认收货
  sure_order: function (result){
    key = result.currentTarget.dataset.key;
    var order_id = result.currentTarget.dataset.order_id;
    
    wx.showModal({
      title: '',
      content: '确定收到货物',
      success: function (res) {
        if (res.confirm) {

          wx.request({
            url: ApiUrl + "/index.php?act=member_order&op=order_receive",
            data: { 'key': key, 'order_id': order_id },
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            method: 'post',
            success: function (res) {
             
              if (res.data.datas == 1) {
                wx.showToast({
                  title: 'ok',
                  icon: 'success',
                  duration: 2000
                })
                wx.redirectTo({
                  url: '/pages/order_detail/order_detail?order_id=' + order_id + "&key=" + key,
                })
              }
            }
          })
        }
      }
    })    
  },
 
  //全部退款
  /*refund_order: function (result) {
    key = result.currentTarget.dataset.key;
    var order_id = result.currentTarget.dataset.order_id;
    wx.showModal({
      title: '',
      content: '确定要取消订单',
      success: function (res) {
        if (res.confirm) {

          wx.request({
            url: ApiUrl + "/index.php?act=member_order&op=order_cancel",
            data: { 'key': key, 'order_id': order_id },
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            method: 'post',
            success: function (res) {
              if (res.data.datas == 1) {
                wx.showToast({
                  title: '取消成功',
                  icon: 'success',
                  duration: 2000
                })
                wx.redirectTo({
                  url: '/pages/order_detail/order_detail?order_id=' + order_id + "&key=" + key,
                })
              }
            }
          })
        }
      }
    })
  }, */
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})